/*
 * @Date: 2024-10-30 15:12:48
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-11-04 15:35:57
 * @Description: 表格字段配置
 */
import { PojoUtils } from '../cfg/PojoUtils'

/**
 * 表格字段选框类型
 */
export class TableColBoxType {
  constructor (label, value, column) {
    this.label=label
    this.value=value
    this.column=column
  }

  static get RADIO() {
    return new TableColBoxType('单选框', 'radio', { type: 'radio', width: 60, align: 'center', slots: { header: 'radio_header' } })
  }
  static get CHECKBOX() {
    return new TableColBoxType('多选框', 'checkbox', { type: 'checkbox', width: 50, align: 'center' })
  }

  /**
   * 比对相同
   * 
   * @param {String|TableColBoxType} param 
   * @returns {Boolean} 
   */
  equals (param) {
    if (param instanceof TableColBoxType) {
      return param.value === this.value
    } else {
      return param === this.value
    }
  }

}

/**
 * 表格字段浮动类型
 */
export class TableColFixedType {
  constructor (label, value) {
    this.label=label
    this.value=value
  }

  static get left() {
    return new TableColFixedType('居左', 'left')
  }
  static get right() {
    return new TableColFixedType('居右', 'right')
  }
}

/**
 * 表格字段居中类型
 */
export class TableColAlignType {
  constructor (label, value) {
    this.label=label
    this.value=value
  }
  static get left() {
    return new TableColAlignType('居左', 'left')
  }
  static get right() {
    return new TableColAlignType('居右', 'right')
  }
  static get center() {
    return new TableColAlignType('居中', 'center')
  }
}


export class TableColTypes {
  /**
   * 获取选框类型的数组
   * 
   * @returns {Array}
   */
  static getBoxTypes () {
    const staticKeys = PojoUtils.getOwnPropertyStatics(TableColBoxType)
    const staticItems = staticKeys.map(key => TableColBoxType[key])
    return staticItems
  }
  /**
   * 获取选框类型的字段数据
   * 
   * @returns {Object}
   */
  static getBoxTypesCol () {
    let res = {}
    this.getBoxTypes().forEach(item => {
      res[item.value] = item.column
    })
    return res
  }
  /**
   * 获取浮动类型的数组
   * 
   * @returns {Array}
   */
  static getFixedTypes () {
    const staticKeys = PojoUtils.getOwnPropertyStatics(TableColFixedType)
    const staticItems = staticKeys.map(key => TableColFixedType[key])
    return staticItems
  }
  /**
   * 获取浮动类型的数据数组
   * 
   * @returns {Array}
   */
  static getFixedTypesValue () {
    return this.getFixedTypes().map(item => item.value)
  }
  /**
   * 获取对齐方式的数组
   * 
   * @returns {Array}
   */
  static getAlignTypes () {
    const staticKeys = PojoUtils.getOwnPropertyStatics(TableColAlignType)
    const staticItems = staticKeys.map(key => TableColAlignType[key])
    return staticItems
  }
  /**
   * 判断是否包含选框类型
   * 
   * @returns {Boolean}
   */
  static includeBoxTypes (type) {
    let resItem = this.getBoxTypes().find(item => item.value === type)
    return resItem ? true : false;
  }
  /**
   * 判断是否包含浮动类型
   * 
   * @returns {Boolean}
   */
  static includeFixedTypes (type) {
    let resItem = this.getFixedTypes().find(item => item.value === type)
    return resItem ? true : false;
  }
}